#ifndef DEVICELIST_H
#define DEVICELIST_H

//#include "device.h"

#include <QAbstractListModel>
#include <QList>
#include <QString>
#include <QHash>
#include <QByteArray>
#include <QDateTime>

class Device{
public:

    Device(QString name_, QString portname_, QString protocol_="A", int addr_=1, QString color_="gray"){
        name = name_;
        portName=portname_;
        protocol=protocol_;
        comAddr = addr_;
        colorCode = color_;
    }
    QString name;
    QString portName;
    QString protocol;
    int comAddr;
    QString colorCode;
    QString SystemTime;
    QString dataString;
};

class DeviceList : public QAbstractListModel
{

    Q_OBJECT

public:
//    QString name;
//    QString portname;
//    QString protocol;
//    int comaddr;
//    QString colorCode;
    enum LineInfo_Roles{
        RoleName =Qt::UserRole + 1,
        RolePortname,
        RoleProtocol,
        RoleCommaddr,
        RolecolorCode,
        RoleSystemTime,
        RoledataString
    };


public:
    explicit DeviceList(QObject *parent = 0);

    int rowCount(const QModelIndex &parent) const;
    int rowCountRead();
    QVariant data(const QModelIndex &index, int role) const;
    QHash<int, QByteArray> roleNames() const;
    Q_INVOKABLE void addDevice(QString name_, QString portname_, QString protocol_, QString addr_);
    QList<Device> getdata(){return m_display_list;}
    void setdata(QList<Device>){}
    void changeDataString(int index,QString str);
    Q_INVOKABLE void changeName(int index);
    Q_INVOKABLE void clickItem(int index);

signals:
    void dataChanged();
public slots:

private:
    QList<Device> m_display_list;
    QHash<int, QByteArray> m_roleNames;
};




#endif // DEVICELIST_H
